package com.bao.springboot.first.web;

import com.bao.springboot.first.domain.User;
import com.bao.springboot.first.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author ：baoliangquan
 * @date ：Created in 2019/11/14 0014 15:08
 * @description：
 * @modified By：
 * @version: $
 */

@Api(tags = "用户管理")
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "获取用户列表")
    @GetMapping(value = "/all")
    public List<User> getAllUser(){
        return userService.getAll();
    }

    @ApiOperation(value = "保存用户信息")
    @PostMapping(value = "/save")
    public String save(@Valid User user){
        int count = userService.save(user);
        return "成功保存"+count+"条数据";
    }

    @ApiOperation(value = "删除用户")
    @GetMapping(value = "/delete")
    public String delete(Long id){
        int count = userService.delete(id);
        return "成功删除"+count+"条数据";
    }

    @ApiOperation(value = "年龄判断")
    @GetMapping(value = "/findUserByLessAge")
    public List<User> findUserByLessAge(String age){
        return userService.findUserByLessAge(age);
    }
}
